package com.rentcarRepair.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eight.pojo.TbMaintainRecord;
import com.eight.pojo.TbMaintainShop;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rentcarRepair.dao.maintainRecordMapper;
import com.rentcarRepair.service.maintainRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author caoch
 * @since 2023/2/27 10:19
 **/
@Service("maintainRecordServiceImpl")
public class maintainRecordServiceImpl extends ServiceImpl<maintainRecordMapper, TbMaintainRecord> implements maintainRecordService {
	@Autowired
	private maintainRecordMapper maintainRecordMapper;

	/**
	 * 添加维修记录
	 * @param record
	 * @return int
	 */
	public int addRecord(TbMaintainRecord record){
		return maintainRecordMapper.insert(record);
	}

	/**
	 * 修改维修记录
	 * @param record
	 * @return int
	 */
	public int updateRecord(TbMaintainRecord record){
		QueryWrapper<TbMaintainRecord> wrapper = new QueryWrapper<>();
		wrapper.eq("id", record.getId());
		return maintainRecordMapper.update(record,wrapper);
	}

	/**
	 * 删除维修记录
	 * @param id
	 * @return int
	 */
	public int removeRecord(int id){
		return maintainRecordMapper.deleteById(id);
	}

	/**
	 * 维修记录查询
	 * @param currentPage
	 * @param pageSize
	 * @param record
	 * @return list
	 */
	public PageInfo<TbMaintainRecord> selectRecord(Integer currentPage, Integer pageSize, TbMaintainRecord record){
		PageHelper.startPage(currentPage,pageSize);
		QueryWrapper<TbMaintainRecord> wrapper = new QueryWrapper<>();
		wrapper.eq(record.getId()!=null,"id",record.getId())
				.or()
				.eq(record.getMaintainShopId()!=null,"maintain_shop_id",record.getMaintainShopId());
		List<TbMaintainRecord> tbMaintainRecords = maintainRecordMapper.selectList(wrapper);
		PageInfo<TbMaintainRecord> tbMaintainRecordPageInfo = new PageInfo<>(tbMaintainRecords);
		return tbMaintainRecordPageInfo;
	}
}
